//
//  CheckBarcodeWriteViewController.m
//  Teacher
//
//  Created by 李飞 on 15/11/4.
//  Copyright (c) 2015年 xueyinyue. All rights reserved.
//

#import "CheckBarcodeWriteViewController.h"
#import "UserBSCheckDeleteTicket.h"

@interface CheckBarcodeWriteViewController ()

@end

@implementation CheckBarcodeWriteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"核销课时券";
    
    
    _okBtn.enabled = NO;
    
    [self initNavegationBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UITextFieldDelegate

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
    
    if (toBeString.length != 0)
    {
        _okBtn.enabled = YES;
    }
    else
    {
        _okBtn.enabled = NO;
    }
    
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


#pragma mark -  NavegationBar
- (void)initNavegationBar
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    backBtn.bounds = CGRectMake(0, 0, 15, 20);
    [backBtn addTarget:self action:@selector(onBackButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setBackgroundImage:[UIImage imageNamed:NAVIGATION_BACKARROW_IMAGE] forState:UIControlStateNormal];

    UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backBarBtn;

}


- (void)onBackButtonClick:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (IBAction)onOkBtnClick:(id)sender {
    
    UserBSCheckDeleteTicket *userBSCheckDeleteTicket = [[UserBSCheckDeleteTicket alloc] init];
    [self showProgressView];
    userBSCheckDeleteTicket.ticketNumber = _codeTF.text;
    
    [self runService:userBSCheckDeleteTicket andComplete:^(EACService *service) {
        [self hideProgressView];
    } andSuccess:^(EACService *service, id o) {
        UserBSCheckDeleteTicketResult* userBSCheckDeleteTicketResult = o;
    
        [self showToastMessage:userBSCheckDeleteTicketResult.message];

    }];
    
}
@end
